package com.fyzk.activity.setting;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.DownloadListener;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.fyzk.base.BaseActivity;
import com.tyjc.lottery.R;
import com.fyzk.utils.HelpUrlConstants;
import com.fyzk.view.TopTitleView;

/**
 * 新版纪要：描述新版功能
 * 
 * @author miao
 * 
 */
public class NewVersionDiscriptionActivity extends BaseActivity {

	TopTitleView topView;
	WebView webView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.new_version_discription);
		topView = (TopTitleView) findViewById(R.id.newversion_top);
		topView.setOnTitleClickListener(this);
		webView = (WebView)findViewById(R.id.newversion_webview);
		webView.loadUrl(HelpUrlConstants.UPDATE_DISCRIPTION);
		WebSettings webSettings = webView.getSettings();
		webSettings.setUseWideViewPort(true);
		webSettings.setLoadWithOverviewMode(true);
		webSettings.setSaveFormData(false);
		// 必须要打开javaScript
		webSettings.setJavaScriptEnabled(true);
		webSettings.setBuiltInZoomControls(true);
		webSettings.setSupportZoom(true);
		webView.setDownloadListener(new DownloadListener() {
            @Override
            public void onDownloadStart(String url, String userAgent, String contentDisposition,
                                        String mimetype, long contentLength) {
                Uri uri = Uri.parse(url);
                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                startActivity(intent);
            }
        });
        webView.setWebViewClient(new MyWebViewClient());
		webView.setWebChromeClient(new MyWebChromeClient());
	}
	
	
	

	private class MyWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return super.shouldOverrideUrlLoading(view, url);
        }
        @Override
        public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {
            return super.shouldOverrideKeyEvent(view, event);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            super.onReceivedError(view, errorCode, description, failingUrl);
        }
    }
	
	
	final class MyWebChromeClient extends WebChromeClient {
//		public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
////			AppToast.getToast().show("html click22  " + message);
//			int lotteryId = 3010;
//			try {
//				lotteryId = Integer.parseInt(message);
//			} catch (Exception e) {
//				L.i(TAG, e.getMessage());
//			}
//
//			toBuy(lotteryId);
//			result.confirm();
//			return true;
//		}
	}


}
